package Smt.BaseDaoImp;

import Smt.BaseDao.BaseDao;
import Smt.BaseDao.BillDao;
import Smt.Util.Bill;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class BillDaoImp implements BillDao {

	BaseDao bd = new BaseDao();
	private ResultSet rs;

	//账单的增删改
	public boolean util(String sql, Object[] u) {
		return bd.util(sql, u);
	}

	//账单的显示
	public ArrayList<Bill> getBillList(Object[] o, String sql) {
		ArrayList<Bill> list = new ArrayList<Bill>();
		try {
			rs = bd.getList(sql, o);
			while (rs.next()) {
				try {
					Bill b = new Bill(rs.getInt("id"), rs.getDouble("price"), rs.getString("unit"), rs.getInt("num"), rs.getString("bname"), rs.getString("description"), rs.getString("sname"), rs.getString("pay"), rs.getDate("dates"));
					list.add(b);
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			bd.closeAll();
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}

	public int BillCount(String name, String pay) {
		String sql = "select count(*) from Bill where name like '%" + name + "%' and pay like '%" + pay + "%'";
		return bd.Count(sql);
	}
}
